package org.ciallo.easytokencore.config;

import org.ciallo.easytokencore.interceptor.EasyContextInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 请求上下文拦截器配置类
 *
 * <p>核心功能：</p>
 * <ul>
 *   <li>注册上下文拦截器到Spring MVC</li>
 *   <li>设置拦截器为最高优先级(Ordered.HIGHEST_PRECEDENCE)</li>
 *   <li>拦截所有请求路径(/**)</li>
 * </ul>
 *
 * <p>配置说明：</p>
 * <ol>
 *   <li>拦截器会在请求处理的最早阶段执行</li>
 *   <li>确保后续拦截器和控制器能获取到正确的请求上下文</li>
 *   <li>自动注入EasyContextInterceptor实现</li>
 * </ol>
 *
 * @Description: 请求上下文拦截器配置
 * @Author: Jukomu
 * @Package: org.ciallo.easytokencore.config
 * @Project: easy-token-demo
 * @Version: 1.0.0
 * @name: ContextInterceptorConfig
 * @Date: 2025-05-06
 * @Filename: ContextInterceptorConfig
 * @see org.ciallo.easytokencore.interceptor.EasyContextInterceptor
 * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurer
 */
@Configuration
public class ContextInterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new EasyContextInterceptor())
                .addPathPatterns("/**")
                .order(0); // 设置为最高优先级，确保最先执行
    }
}
